package com.learn.ioc;

import com.learn.ioc.autowire.ClassRoom;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import java.util.Arrays;

/**
 * @author gqzdev
 * @date 2021/10/08 16:45
 **/
public class IocTest {

	public static void main(String[] args) {
		AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);
		Arrays.stream(context.getBeanDefinitionNames()).forEach(s -> System.out.println(s));
		ClassRoom classRoom = context.getBean("classRoom", ClassRoom.class);
		System.out.println(classRoom.toString());
	}
}
/* Output:
1. BeanNameAware's setBeanName >>>helloAware
2. BeanClassLoaderAware's setBeanClassLoader >>>sun.misc.Launcher$AppClassLoader@73d16e93
3. BeanFactoryAware's setBeanFactory >>>org.springframework.beans.factory.support.DefaultListableBeanFactory@7f9a81e8: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.event.internalEventListenerProcessor,org.springframework.context.event.internalEventListenerFactory,appConfig,javaConfig,student01,classRoom,hello,helloAware,teacherBean,myFactoryBean,user]; root of factory hierarchy
4. EnvironmentAware's setEnvironment >>>StandardEnvironment {activeProfiles=[], defaultProfiles=[default], propertySources=[PropertiesPropertySource {name='systemProperties'}, SystemEnvironmentPropertySource {name='systemEnvironment'}]}
5. EmbeddedValueResolverAware's setEmbeddedValueResolver >>>org.springframework.beans.factory.config.EmbeddedValueResolver@77a57272
6. ResourceLoaderAware's setResourceLoader (only applicable when running in an application context) >>>org.springframework.context.annotation.AnnotationConfigApplicationContext@65b3120a, started on Wed Nov 10 19:42:24 CST 2021
7. ApplicationEventPublisherAware's setApplicationEventPublisher (only applicable when running in an application context) >>>null
8. MessageSourceAware's setMessageSource (only applicable when running in an application context) >>>org.springframework.context.annotation.AnnotationConfigApplicationContext@65b3120a, started on Wed Nov 10 19:42:24 CST 2021
9. ApplicationContextAware's setApplicationContext (only applicable when running in an application context) >>>org.springframework.context.annotation.AnnotationConfigApplicationContext@65b3120a, started on Wed Nov 10 19:42:24 CST 2021
12.InitializingBean's afterPropertiesSet >>>自定义初始化方法，在init-method之前执行
10.BeanFactoryPostProcessor...postProcessBeanFactory...
	 initMethod >>>Generic bean: class [com.learn.ioc.aware.HelloAware]; scope=singleton; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=initMethod; destroyMethodName=null; defined in file [F:\code\spring-framework-analysis\learn-ioc\build\classes\java\main\com\learn\ioc\aware\HelloAware.class]
	 当前BeanFactory中有14 个Bean [org.springframework.context.annotation.internalConfigurationAnnotationProcessor, org.springframework.context.annotation.internalAutowiredAnnotationProcessor, org.springframework.context.annotation.internalCommonAnnotationProcessor, org.springframework.context.event.internalEventListenerProcessor, org.springframework.context.event.internalEventListenerFactory, appConfig, javaConfig, student01, classRoom, hello, helloAware, teacherBean, myFactoryBean, user]
11.postProcessBeforeInitialization methods of BeanPostProcessors >>>appConfig=>com.learn.ioc.AppConfig@314c508a
14.postProcessAfterInitialization methods of BeanPostProcessors >>>appConfig=>com.learn.ioc.AppConfig@314c508a
11.postProcessBeforeInitialization methods of BeanPostProcessors >>>javaConfig=>com.learn.ioc.annotation.JavaConfig$$EnhancerBySpringCGLIB$$d98daa0d@453da22c
14.postProcessAfterInitialization methods of BeanPostProcessors >>>javaConfig=>com.learn.ioc.annotation.JavaConfig$$EnhancerBySpringCGLIB$$d98daa0d@453da22c
11.postProcessBeforeInitialization methods of BeanPostProcessors >>>student01=>com.learn.ioc.annotation.Student@442675e1
14.postProcessAfterInitialization methods of BeanPostProcessors >>>student01=>com.learn.ioc.annotation.Student@442675e1
11.postProcessBeforeInitialization methods of BeanPostProcessors >>>myFactoryBean=>com.learn.ioc.config.MyFactoryBean@78a2da20
14.postProcessAfterInitialization methods of BeanPostProcessors >>>myFactoryBean=>com.learn.ioc.config.MyFactoryBean@78a2da20
-----可以进行一系列的操作-----
14.postProcessAfterInitialization methods of BeanPostProcessors >>>myFactoryBean=>Student{sid=2020, sname='gqzdev', age=23, addr='湖北黄冈'}
11.postProcessBeforeInitialization methods of BeanPostProcessors >>>teacherBean=>TeacherBean{tid=0, tname='null', course='null'}
14.postProcessAfterInitialization methods of BeanPostProcessors >>>teacherBean=>TeacherBean{tid=0, tname='null', course='null'}
11.postProcessBeforeInitialization methods of BeanPostProcessors >>>classRoom=>ClassRoom{student=Student{sid=2020, sname='gqzdev', age=23, addr='湖北黄冈'}, teacher=TeacherBean{tid=0, tname='null', course='null'}}
14.postProcessAfterInitialization methods of BeanPostProcessors >>>classRoom=>ClassRoom{student=Student{sid=2020, sname='gqzdev', age=23, addr='湖北黄冈'}, teacher=TeacherBean{tid=0, tname='null', course='null'}}
11.postProcessBeforeInitialization methods of BeanPostProcessors >>>hello=>com.learn.ioc.aware.Hello$$EnhancerBySpringCGLIB$$2b0775cc@ba8d91c
14.postProcessAfterInitialization methods of BeanPostProcessors >>>hello=>com.learn.ioc.aware.Hello$$EnhancerBySpringCGLIB$$2b0775cc@ba8d91c
11.postProcessBeforeInitialization methods of BeanPostProcessors >>>user=>User{uid=101, username='ganquanzhong', pwd='pwd', tel='13995978321', addr='china'}
【user-afterPropertiesSet】-实现InitializingBean接口的afterPropertiesSet方法，在bean初始化会自动调用该方法！
【user-initMethod】-在bean被spring容器初始化时，会执行initMethod属性指定的方法！
14.postProcessAfterInitialization methods of BeanPostProcessors >>>user=>User{uid=101, username='ganquanzhong', pwd='pwd', tel='13995978321', addr='china'}
org.springframework.context.annotation.internalConfigurationAnnotationProcessor
org.springframework.context.annotation.internalAutowiredAnnotationProcessor
org.springframework.context.annotation.internalCommonAnnotationProcessor
org.springframework.context.event.internalEventListenerProcessor
org.springframework.context.event.internalEventListenerFactory
appConfig
javaConfig
student01
classRoom
hello
helloAware
teacherBean
myFactoryBean
user
ClassRoom{student=Student{sid=2020, sname='gqzdev', age=23, addr='湖北黄冈'}, teacher=TeacherBean{tid=0, tname='null', course='null'}}
*///~